//星期转换
export const weekConversion = (data) => {
	// //console.log(data,888)
	let acData = data.split('-').join('/')
	data = acData
	let weeks = {
		"0": '星期日',
		"1": '星期一',
		"2": '星期二',
		"3": '星期三',
		"4": '星期四',
		"5": '星期五',
		"6": '星期六',
	}
	let date = new Date(data);
	let nowdate = new Date(Date.now());
	let weekIndex = date.getDay();
	let nowIndex = nowdate.getDay();
	if (weekIndex == nowIndex) {
		return '';
	} else if (nowIndex - weekIndex == 1 || (nowIndex == 0 && weekIndex == 6)) {
		return '昨天';
	} else {
		return weeks[weekIndex];
	}
}
//上午下午转换
export const morningAfternoon = (data) => {
	let acData = data.split('-').join('/')
	data = acData
	let time = data.split(' ')[1].split(":")[0]
	// 0-12 点上午
	// 12点到18下午
	if (time >=12 && time <=18) {
		return '下午'
	} else if (time>=0 && time <12){
		return '上午'
	}else{
		return '晚上'
	}
}
//截取小时日期
export const spliceHours = (data) => {
	let acData = data.split('-').join('/')
	data = acData
	let time = data.split(' ')[1].split(':')
	return time[0] + ':' + time[1]
}
//判断时间差
export const timeDifference = (data) => {
	let acData = data.split('-').join('/')
	data = acData
	// 获取当前日期
	let date = new Date()
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	//获取需要格式化的日期
	let nowYear = data.split(" ")[0].split('/')[0]
	let nowMonth = data.split(" ")[0].split('/')[1]
	let nowDay = data.split(" ")[0].split('/')[2]
	let dateDifference = day - nowDay
	let week = weekConversion(data)
	let APM = morningAfternoon(data)
	let hours = spliceHours(data)
	let timeNum = Math.floor((new Date(Date.now()).getTime() - new Date(data).getTime()) / (1000 * 60 * 60))
	if (timeNum < 1) {
		return '今天 ' + APM + hours
	}
	if (year == nowYear && month == nowMonth && dateDifference <= 7) {
		let week = weekConversion(data)
		let APM = morningAfternoon(data)
		let hours = spliceHours(data)
		return week + ' ' + APM + hours
	}
	if (year > nowYear) {
		return nowYear + '年 ' + nowMonth + '月' + nowDay + '日 ' + hours
	}
	if (month > nowMonth || dateDifference > 7) {
		return nowMonth + '月' + nowDay + '日 ' + hours
	}
	if (dateDifference == 0) {
		return hours
	}

}
